<?php

/**
 * This is the model class for table "loaitin".
 *
 * The followings are the available columns in table 'loaitin':
 * @property integer $IDloaitin
 * @property string $tenloaitin
 * @property integer $thutu
 * @property integer $trangthai
 */
class Loaitin extends CActiveRecord
{
        const TT_AN = 0;
        const TT_HIEN = 11;
        
        public function getTrangthai()
        {
            return array(
            self::TT_HIEN=>'Hiện',
            self::TT_AN=>'Ẩn',
            );
        }
        
        const TT1 = 1;
        const TT2 = 2;
        const TT3 = 3;
        const TT4 = 4;
        const TT5 = 5;
        const TT6 = 6;
        const TT7 = 7;
        const TT8 = 8;
        const TT9 = 9;
        const TT10 = 10;
        
        public function getThutu()
        {
            return array(
            self::TT1=>'1',
            self::TT2=>'2',
            self::TT3=>'3',
            self::TT4=>'4',
            self::TT5=>'5',
            self::TT6=>'6',
            self::TT7=>'7',
            self::TT8=>'8',
            self::TT9=>'9',
            self::TT10=>'10',
            );
        }
        
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'loaitin';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('thutu, trangthai', 'numerical', 'integerOnly'=>true),
                        array( 'tenloaitin, thutu, trangthai','required'),
			array('tenloaitin', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('IDloaitin, tenloaitin, thutu, trangthai', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
                
                return array('baiviet' => array(self::HAS_MANY, 'baiviet', 'IDloaitin'),);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'IDloaitin' => 'Idloaitin',
			'tenloaitin' => 'Loại Tin',
			'thutu' => 'Thứ tự',
			'trangthai' => 'Trạng Thái',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('IDloaitin',$this->IDloaitin);
		$criteria->compare('tenloaitin',$this->tenloaitin,true);
		$criteria->compare('thutu',$this->thutu);
		$criteria->compare('trangthai',$this->trangthai);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Loaitin the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
